import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';

import '../../../../../../model/build_info.dart';
import '../../../../../../model/lift_info.dart';
import 'status_logic.dart';

class StatusPage extends StatelessWidget{
  var logic;

  StatusPage({Key? key,required BuildInfo buildInfo, required LiftInfo liftInfo}) : super(key: key){
    Get.delete<StatusLogic>();
    logic = Get.put(StatusLogic());
    logic.buildInfo = buildInfo;
    logic.liftInfo = liftInfo;
  }

  @override
  Widget build(BuildContext context) {
    Size size = MediaQuery.of(context).size;
    int space = 24;
    double itemW = (size.width - 3 * space) / 2;
    if(0==logic.liftInfo.liftType){
      return buildLiftView(itemW);
    }else{
      return buildLift1View(itemW);
    }
  }

  buildLiftView(double itemW) {
    return Container(
      margin: EdgeInsets.symmetric(vertical: 10),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          Container(
            alignment: Alignment.center,
            width: itemW,
            child:Column(
              children: [
                Container(
                  decoration: BoxDecoration(
                      color: Color.fromARGB(255, 152, 212, 172),
                      border: topBorder()),
                  height: 50,
                  alignment: Alignment.center,
                  child: Text('SVP SIGN'),
                ),
              GetBuilder<StatusLogic>(
                init: logic,
                id: logic.ID_LIFT_INFO,
                builder: (StatusLogic controller) {
                  return Expanded( child: ListView.builder(
                      itemCount: logic.liftInfo.spvAlermList.length,
                      itemBuilder: (context, index) {
                        var data = logic.liftInfo.spvAlermList[index];
                        return Container(
                          decoration: BoxDecoration(
                              color: data.getBgColor(),
                              border: mildBorder()),
                          height: 50,
                          alignment: Alignment.center,
                          child: Center(child: Text(data.lNameEn)),
                        );}
                  ));
                })]
            )
          ),
          Container(
              alignment: Alignment.center,
              width: itemW,
              child:Column(
                  children: [
                    Container(
                      decoration: BoxDecoration(
                          color: Color.fromARGB(255, 152, 212, 172),
                          border: topBorder()),
                      height: 50,
                      alignment: Alignment.center,
                      child: Text('TPC-500 Signal'),
                    ),
                    GetBuilder<StatusLogic>(
                        init: logic,
                        id: logic.ID_LIFT_INFO,
                        builder: (StatusLogic controller) {
                          return Container(
                            decoration: BoxDecoration(
                                color: Colors.white,
                                border: mildBorder()),
                            height: 50,
                            alignment: Alignment.center,
                            child: Center(child: Text(logic.liftInfo.getSpeedName())),
                          );
                        }),
                    GetBuilder<StatusLogic>(
                        init: logic,
                        id: logic.ID_LIFT_INFO,
                        builder: (StatusLogic controller) {
                          return Container(
                            decoration: BoxDecoration(
                                color: Colors.white,
                                border: mildBorder()),
                            height: 50,
                            alignment: Alignment.center,
                            child: Center(child: Text(logic.liftInfo.getLoadName())),
                          );
                      }),
                    GetBuilder<StatusLogic>(
                        init: logic,
                        id: logic.ID_LIFT_INFO,
                        builder: (StatusLogic controller) {
                          return Expanded( child: ListView.builder(
                              itemCount: logic.liftInfo.tpcAlermList.length,
                              itemBuilder: (context, index) {
                              var data = logic.liftInfo.tpcAlermList[index];
                              return Container(
                                decoration: BoxDecoration(
                                    color: data.getBgColor(),
                                    border: mildBorder()),
                                height: 50,
                                alignment: Alignment.center,
                                child: Center(child: Text(data.lNameEn)),
                              );}
                          ));
                        })
                  ]
              )
          ),
        ],
      ),
    );
  }

  buildLift1View(double itemW) {
    return Container(
        child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Container(
                ///楼盘 工作区 横向list
                margin: const EdgeInsets.fromLTRB(0, 20, 0, 30),
                height: 56,
                color: Colors.transparent,
                child: Image(image: AssetImage(logic.getImage()), width: 640),
              ),
              Flexible(child:Container(
                  alignment: Alignment.center,
                  width: itemW,
                  child:Column(
                      children: [
                        Container(
                          decoration: BoxDecoration(
                              color: Color.fromARGB(255, 152, 212, 172),
                              border: topBorder()),
                          height: 50,
                          alignment: Alignment.center,
                          child: Text('SVP SIGN'),
                        ),
                        GetBuilder<StatusLogic>(
                            id: logic.ID_LIFT_INFO,
                            builder: (StatusLogic controller) {
                              return Expanded( child: ListView.builder(
                                  itemCount: logic.liftInfo.spvAlermList.length,
                                  itemBuilder: (context, index) {
                                    var data = logic.liftInfo.spvAlermList[index];
                                    return Container(
                                      decoration: BoxDecoration(
                                          color: data.getBgColor(),
                                          border: mildBorder()),
                                      height: 50,
                                      alignment: Alignment.center,
                                      child: Center(child: Text(data.sName)),
                                    );}
                              ));
                            })]
                  )
              )),
            ]));


  }

  Border mildBorder() {
    return const Border(left: BorderSide(width: 1, color: Colors.black), right: BorderSide(width: 1, color: Colors.black), bottom: BorderSide(width: 1, color: Colors.black));
  }

  Border topBorder() {
    return Border.all(width: 1, color: Colors.black);
  }




}
